package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.interceptor.UserParam;
import cn.wolfcode.wolf2w.query.TravelQueryObject;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @RequestMapping("list")
    public Object getContentById(Model model , @ModelAttribute("qo") TravelQueryObject qo){
        Page<Travel> page = travelService.query(qo);
        model.addAttribute("page" , page);
        return "travel/list";
    }

    @RequestMapping("audit")
    @ResponseBody
    public Object audit(String id , int state){
        travelService.audit(id , state);
        return JsonResult.success();
    }


    @RequestMapping("updateStateBtn")
    @ResponseBody
    public Object updateStateBtn(String id , int state){
        travelService.updateStateBtn(id , state);
        return JsonResult.success();
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public Object getContentById(String id){
        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }

}
